package com.iwhalecloud.bss.kite.cucc.service.biz;

import com.alibaba.fastjson.JSON;
import com.iwhalecloud.bss.kite.cart.common.util.KiteSessionUtil;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.cucc.client.api.biz.IBizService;
import com.iwhalecloud.bss.kite.cucc.common.callclient.HttpsCallClient;
import com.iwhalecloud.bss.kite.cucc.common.callclient.constant.CallClientEnum;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalCallClientEnum;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yangwj
 * @date 2020/5/12 10:37
 */
@Service
public class BizServiceImpl implements IBizService {

    @Override
    public Map<String, Object> getBizServiceList(String orderId) {
        //请求参数
        Map<String, String> header = new HashMap<>(1024);
        header.put("Cookie", "SESSION=" + KiteSessionUtil.getLocalSessionId());
        Map<String, String> param = new HashMap<>(1024);
        param.put("orderId",orderId);

        //发送Get请求
        String rsp = HttpsCallClient.getString(LocalCallClientEnum.QRY_BIZ_SERVICE_LIST, param, header);

        Map<String, Object> orderMap = JSON.parseObject(rsp, Map.class);
        if (rsp == null) {
            ErrorConsts.INF_INVOKE_ERROR.throwOut(CallClientEnum.QRY_ORDER_DETAIL.getServiceCode(), "获取业务列表", "获取业务列表失败");
        }
        Map<String, Object> dataMap = (Map<String, Object>) orderMap.get("data");
        if (dataMap == null) {
            ErrorConsts.INF_INVOKE_ERROR.throwOut(CallClientEnum.QRY_ORDER_DETAIL.getServiceCode(), "获取业务列表", "获取业务列表失败");
        }
        return dataMap;
    }
}
